<?php

$SymbolConstants = array(
	"SYMBOL_EOF" => "\n", // (EOF)
        "SYMBOL_NULL" => "", // (Error)
        "SYMBOL_WHITESPACE" => " ", // (Whitespace)
        "SYMBOL_COMMENTEND" => "*/", // (Comment End)
        "SYMBOL_COMMENTLINE" => "//", // (Comment Line)
        "SYMBOL_COMMENTSTART" => "/*", // (Comment Start)
        "SYMBOL_MINUS" => 6, // '-'
        "SYMBOL_EXCLAMEQ" => 7, // '!=>'
        "SYMBOL_PERCENT" => 8, // '%'
        "SYMBOL_AMPAMP" => 9, // '&&'
        "SYMBOL_LPARAN" => 10, // '('
        "SYMBOL_RPARAN" => 11, // ')'
        "SYMBOL_TIMES" => 12, // '*'
        "SYMBOL_COMMA" => 13, // ','
        "SYMBOL_DOT" => 14, // '.'
        "SYMBOL_DIV" => 15, // '/'
        "SYMBOL_SEMI" => 16, // ';'
        "SYMBOL_LBRACKET" => 17, // '['
        "SYMBOL_RBRACKET" => 18, // ']'
        "SYMBOL_LBRACE" => 19, // '{'
        "SYMBOL_PIPEPIPE" => 20, // '||'
        "SYMBOL_RBRACE" => 21, // '}'
        "SYMBOL_PLUS" => 22, // '+'
        "SYMBOL_LT" => 23, // '<'
        "SYMBOL_LTEQ" => 24, // '<=>'
        "SYMBOL_EQ" => 25, // '=>'
        "SYMBOL_EQEQ" => 26, // '=>=>'
        "SYMBOL_GT" => 27, // '>'
        "SYMBOL_GTEQ" => 28, // '>=>'
        "SYMBOL_BOOLEAN" => 29, // boolean
        "SYMBOL_CHAR" => 30, // char
        "SYMBOL_CHARACTER" => 31, // character
        "SYMBOL_CLASS" => 32, // class
        "SYMBOL_ELSE" => 33, // else
        "SYMBOL_FALSE" => 34, // false
        "SYMBOL_ID" => 35, // id
        "SYMBOL_IF" => "if", // if
        "SYMBOL_INT" => 37, // int
        "SYMBOL_NUM" => 38, // num
        "SYMBOL_PROGRAM" => 39, // Program
        "SYMBOL_RETURN" => 40, // return
        "SYMBOL_STRUCT" => 41, // struct
        "SYMBOL_TRUE" => 42, // true
        "SYMBOL_VOID" => 43, // void
        "SYMBOL_WHILE" => 44, // while
        "SYMBOL_ADDEXP" => 45, // <addExp>
        "SYMBOL_ARG" => 46, // <arg>
        "SYMBOL_BLOCK" => 47, // <block>
        "SYMBOL_BOOL_LITERAL" => 48, // <bool_literal>
        "SYMBOL_BOOLEXP" => 49, // <boolExp>
        "SYMBOL_CHAR_LITERAL" => 50, // <char_literal>
        "SYMBOL_DECLARATION" => 51, // <declaration>
        "SYMBOL_EXPRESSION" => 52, // <expression>
        "SYMBOL_IDEXPRESSION" => 53, // <idExpression>
        "SYMBOL_INT_LITERAL" => 54, // <int_literal>
        "SYMBOL_KLEENARG" => 55, // <kleenArg>
        "SYMBOL_KLEENARGC" => 56, // <kleenArgC>
        "SYMBOL_KLEENDECLARATION" => 57, // <kleenDeclaration>
        "SYMBOL_KLEENPARAMETER" => 58, // <kleenParameter>
        "SYMBOL_KLEENPARAMETERC" => 59, // <kleenParameterC>
        "SYMBOL_KLEENSTATEMENT" => 60, // <kleenStatement>
        "SYMBOL_KLEENVARDECLARATION" => 61, // <kleenVarDeclaration>
        "SYMBOL_LITERAL" => 62, // <literal>
        "SYMBOL_LOCATION" => 63, // <location>
        "SYMBOL_LOCKDOTLOCATION" => 64, // <lockDotLocation>
        "SYMBOL_LOCKELSEBLOCK" => 65, // <lockElseBlock>
        "SYMBOL_LOCKEXPRESSION" => 66, // <lockExpression>
        "SYMBOL_METHODCALL" => 67, // <methodCall>
        "SYMBOL_METHODDECLARATION" => 68, // <methodDeclaration>
        "SYMBOL_MULTEXP" => 69, // <multExp>
        "SYMBOL_NEGATEEXP" => 70, // <negateExp>
        "SYMBOL_PARAMETER" => 71, // <parameter>
        "SYMBOL_PROGRAM2" => 72, // <Program>
        "SYMBOL_STATEMENT" => 73, // <statement>
        "SYMBOL_STRUCTDECLARATION" => 74, // <structDeclaration>
        "SYMBOL_TYPE" => 75, // <type>
        "SYMBOL_VALUE" => 76, // <value>
        "SYMBOL_VARDECLARATION" => 77  // <varDeclaration>
	);


function Parse($string)
{

        global $SymbolConstants;

        $lines = explode("\n", $string);
        $count_lines = count($lines);

        $CommentStart = false;
        for($i=0; $i<$count_lines; $i++)
        {
                $count_string = strlen($lines[$i]);

                for($j=0; $j<$count_string; $j++)
                {
                        if(substr($lines[$i], $j, strlen($SymbolConstants["SYMBOL_COMMENTEND"])) == $SymbolConstants["SYMBOL_COMMENTEND"])
                        {
                                $CommentStart = false;
                                $j += strlen($SymbolConstants["SYMBOL_COMMENTEND"]) - 1;
                        }
                        else if($CommentStart)
                        {

                        }
                        else if(substr($lines[$i], $j, strlen($SymbolConstants["SYMBOL_WHITESPACE"])) == $SymbolConstants["SYMBOL_WHITESPACE"])
                        {

                        }
                        else if(substr($lines[$i], $j, strlen($SymbolConstants["SYMBOL_COMMENTLINE"])) == $SymbolConstants["SYMBOL_COMMENTLINE"])
                        {
                                break;
                        }
                        else if(substr($lines[$i], $j, strlen($SymbolConstants["SYMBOL_COMMENTSTART"])) == $SymbolConstants["SYMBOL_COMMENTSTART"])
                        {
                                $CommentStart = true;
                                $j += strlen($SymbolConstants["SYMBOL_COMMENTSTART"]) - 1;
                        }
                        else if(substr($lines[$i], $j, strlen($SymbolConstants["SYMBOL_IF"])) == $SymbolConstants["SYMBOL_IF"])
                        {
                                echo $j." ";
                                $j += strlen($SymbolConstants["SYMBOL_IF"]) - 1;
                        }else
                        {
                               echo "Unknown symbol : ".substr($lines[$i], $j, 1)." - $j <br>";
                        }
                }
        }
}

Parse("  if  
        ");

?>